package com.innovation.chengzhangriji.ui.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.widget.ImageButton;

import com.innovation.chengzhangriji.R;

public class CuteTwoImageButton extends ImageButton {

    /*未选中的图片*/
    private Drawable mCuteOneBackground;

    /*选中后的图片*/
    private Drawable mCuteTwoBackground;

    private boolean isSelect;

    public CuteTwoImageButton(Context context) {
        super(context);
        init(context, null);
    }

    public CuteTwoImageButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public CuteTwoImageButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs);
    }

    public void setTwoDrawable(Drawable drawable1, Drawable drawable2) {
        mCuteOneBackground = drawable1;
        mCuteTwoBackground = drawable2;
    }

    /**
     * 设置为状态一
     */
    public void setOneState() {
        if (mCuteOneBackground != null) {
            setImageDrawable(mCuteOneBackground);
            isSelect = false;
        }
    }

    /**
     * 设置为状态二
     */
    public void setTwoState() {
        if (mCuteTwoBackground != null) {
            setImageDrawable(mCuteTwoBackground);
            isSelect = true;
        }
    }

    public boolean isSelect() {
        return isSelect;
    }

    private void init(Context context, AttributeSet attrs) {
        setBackgroundDrawable(null);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.CuteTwoImageButton);
        mCuteOneBackground = typedArray.getDrawable(R.styleable.CuteTwoImageButton_cute_one_image_background);
        mCuteTwoBackground = typedArray.getDrawable(R.styleable.CuteTwoImageButton_cute_two_image_background);
        typedArray.recycle();
        setOneState();
    }
}
